<template>
	<view>
		<view class="index_card">
			<image mode="aspectFill" class="index_user_img" :src="userInfo.headimg" @tap="go('/pages/center/center')"></image>
			<view class="index_userinfo" @tap="go('/pages/center/center')">
				<view class="index_username">{{userInfo.username}}</view>
				<view class="index_lv">
					<text>服务等级：</text>
					<image :src="userInfo.score > 0 ? '/static/images/star.png' : '/static/images/unstar.png'"></image>
					<image :src="userInfo.score > 1 ? '/static/images/star.png' : '/static/images/unstar.png'"></image>
					<image :src="userInfo.score > 2 ? '/static/images/star.png' : '/static/images/unstar.png'"></image>
					<image :src="userInfo.score > 3 ? '/static/images/star.png' : '/static/images/unstar.png'"></image>
					<image :src="userInfo.score > 4 ? '/static/images/star.png' : '/static/images/unstar.png'"></image>
					<text>{{userInfo.score}}星</text>
				</view>
			</view>
			<image src="/static/images/code.png" class="index_code" @tap="getCode()"></image>
		</view>

		<view class="index_list">
			<block v-for="(item,index) in list">
				<view class="index_item" v-if="checkPermission([item.id])" @tap="go(item.url)" :key='index'>
					<image :src="item.src"></image>
					<view>{{item.text}}</view>
				</view>
			</block>
		</view>

		<image src="/static/images/logo.png" class="index_logo"></image>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				load: {
					loadStatus: false,
					loadType: 3,
					loadAnimation: "monster"
				},
				list: [{
						src: "/static/images/index001.png",
						text: "客户",
						url: "/pages/client/client",
						id:10000
					},
					{
						src: "/static/images/index002.png",
						text: "商机客户",
						url: "/pages/opportunity/opportunity",
						id:20000
					},
					{
						src: "/static/images/index003.png",
						text: "工单",
						url: "/pages/work/work",
						id:30000
					},
					{
						src: "/static/images/index004.png",
						text: "订单",
						url: "/pages/order/order",
						id:40000
					},
					{
						src: "/static/images/index005.png",
						text: "配件",
						url: "/pages/accessories/accessories",
						id:50000
					},
					{
						src: "/static/images/index006.png",
						text: "产品",
						url: "/pages/product/product",
						id:60000
					},
					{ 
						src: "/static/images/index007.png",
						text: "财务",
						url: "/pages/finance/finance",
						id:70000
					},
					{
						src: "/static/images/index008.png",
						text: "统计",
						url: "/pages/statistics/statistics",
						id:80000
					},
					{
						src: "/static/images/index009.png",
						text: "资料库",
						url: "/pages/library/library",
						id:90000
					},
					{
						src: "/static/images/index010.png",
						text: "退换货",
						url: "/pages/return/return",
						id:100000
					},
					// {src:"/static/images/index011.png",text:"库存",url:""},
				],
				userInfo: {
					headimg: "",
					score: ""
				},
				auth:[]
			}
		},
		onLoad() {
			this.$api.getUserInfo({
				user_id: uni.getStorageSync("userId")
			}).then(res => {
				//console.log("--权限-->>>>",res.auth);
				this.userInfo = res;
				this.auth = res.auth;
				this.$app.globalData.userInfo = res
				this.$store.dispatch('setRoles',res.auth);
				this.$store.dispatch('setUserInfo',res);
				this.havingAudit();
				this.havingApproval();
			}) 
		},
		onShow() {
			uni.hideHomeButton();
		},
		methods: {
			go(url) { //页面跳转
				url += "?userId=" + this.$app.globalData.userId
				uni.navigateTo({
					url
				}) 
			},
			lookImg() {
				uni.previewImage({
					urls: [this.userInfo.headimg]
				})
			},
			getCode() { //获取二维码数据
				uni.scanCode({
					success(res) {
						console.log(res)
					}
				})
			},
			havingAudit(){ // 是否有审核

				var authArray= this.auth;

				for(let i in authArray){
					if(authArray[i].table_id == 100000){

						for(let j in authArray[i].datas){

							if(authArray[i].datas[j] == 100006){ // 审核100006
								this.$app.globalData.isAudit = 1;
								return;
							}

						}

					}
				}
				this.$app.globalData.isAudit = -1;
				return;
			},
			havingApproval(){ // 是否有审批

				var authArray= this.auth;

				for(let i in authArray){
					if(authArray[i].table_id == 100000){

						for(let j in authArray[i].datas){

							if(authArray[i].datas[j] == 100003){ // 审批100003
								this.$app.globalData.isApproval = 1;
								return;
							}

						}

					}
				}
				this.$app.globalData.isApproval = -1;
				return;
			}
		}
	}
</script>

<style>
	.index_card {
		width: 100%;
		padding: 40upx 30upx 100upx 30upx;
		background: #049BFF;
		display: flex;
		flex-direction: row;
		align-items: center;
		box-sizing: border-box;
	}

	.index_user_img {
		width: 116upx;
		height: 116upx;
		background: #FFFFFF;
		border-radius: 50%;
	}

	.index_userinfo {
		color: #fff;
		margin-left: 24upx;
		flex-grow: 1;
	}

	.index_lv {
		display: flex;
		flex-direction: row;
		align-items: center;
		width: 100%;
		margin-top: 10upx;
		font-size: 22upx;
	}

	.index_lv image {
		width: 26upx;
		height: 26upx;
		margin-right: 10upx;
	}

	.index_code {
		width: 40upx;
		height: 40upx;
		background: #fff;
		padding: 30upx;
		border-radius: 50%;
	}

	.index_list {
		width: 100%;
		padding-top: 60upx;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		background: #FFFFFF;
		border-radius: 28upx 28upx 0 0;
		margin-top: -28upx;
	}

	.index_item {
		width: 25%;
		padding-bottom: 50upx;
		text-align: center;
		font-size: 26upx;
		color: #333333;
	}

	.index_item image {
		width: 60upx;
		height: 60upx;
		margin-bottom: 5upx;
	}

	.index_logo {
		width: 234upx;
		height: 58upx;
		margin-top: 100upx;
		margin-left: 258upx;
	}
</style>
